package com.soft.testmybatis.mapper;

import com.soft.testmybatis.entity.Items;
import com.soft.testmybatis.entity.OrderDetail;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderDetailMapper {

    // 根据订单明细，关联查询商品信息
    OrderDetail findOrderDetailAndItemById(int id);

    // 根据订单明细，关联查询订单信息
    OrderDetail findOrderDetailAndOrderById(int id);

    @Select("select * from orderdetail where orders_id = #{id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "ordersId", column = "orders_id"),
            @Result(property = "itemsId", column = "items_id"),
            @Result(property = "itemsNum", column = "items_num"),
            @Result(property = "item", column = "items_id",
                    javaType = Items.class,
                    one = @One(select = "com.soft.testmybatis.mapper.ItemsMapper.findItemById"))
    })
    List<OrderDetail> findOrderDetailsById(int id);

}
